<?php
class label_advertisingModel extends baseModel{
    protected $table = 'advertising_category';

    public function advertising_list($data){
        $where=array();
        if(!empty($data['sign'])){
            $where['sign'] = ' AND B.sign="'.$data['sign'].'" ';
        }else{
            return array();
        }
        if (!empty($data['where'])) {
            $where['where'] = ' AND '.$data['where'];
        }
        if (!empty($data['limit'])) {
            $where['limit'] = $data['limit'];
        }else{
            $where['limit'] = 10;
        }
        if (!empty($data['order'])) {
            if(substr($where['order'],1)=='A'){
                $where['order']='A.'.$where['order'].',A.sequence ASC,A.id.ASC';
            }else{
                $where['order'] = $data['order'].',A.sequence ASC,A.id.ASC';
            }
        }else{
            $where['order'] = 'A.sequence ASC,A.id.ASC';
        }

        $condition=$where['sign'].$where['where'];
        $condition=substr($condition,4);
        $sql="
            SELECT {$ext_field}{$content_field}A.*,B.type,B.sign
            FROM {$this->model->pre}advertising A 
            LEFT JOIN {$this->model->pre}advertising_category B ON A.cid = B.id
            WHERE {$condition} ORDER BY {$where['order']} LIMIT {$where['limit']}
            ";
        $data=$this->query($sql);
        if(!empty($data)){
            $i=0;
            foreach ($data as $key=>$value) {
                $i++;
                if(!empty($info['stop_time'])){
                    if($info['start_time']>time()){
                        continue;
                    }
                }
                if(!empty($info['stop_time'])){
                    if($info['stop_time']<time()){
                        continue;
                    }
                }
                $list[$key]=model('advertising')->get_format_data($value);
                $list[$key]['i']=$i;
            }
        }
        return $list;
    }

}

?>